package org.mobile.servlets;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mobile.beans.Order;
import org.mobile.beans.User;
import org.mobile.logic.OrderLogic;

/**
 * Servlet implementation class GetMyOrders
 */
@WebServlet(name = "getMyOrders", urlPatterns = { "/getMyOrders" })
public class GetMyOrders extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetMyOrders() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int userID= ((User)request.getSession().getAttribute("user")).getId();
		List<Order> orderList= OrderLogic.getInstance().getOrders(userID);
		if(orderList != null){
			request.getSession().setAttribute("user_orders", orderList);
			request.getRequestDispatcher("transactions.jsp").forward(request, response);
		}
		else{
			request.setAttribute("error", "Błąd wczytywania zamówień!");
			request.getRequestDispatcher("errPage.jsp").forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

}
